<template>
	<xh-list-container
		ref="pageList"
		title="面料入库"
		:request="request"
		@clickAdd="handleClickAdd"
		@request="handleRequest"
		:columns="columns"
		rowKey="fabricId"
	>
		<template v-slot="scope">
			<xh-list-item
				v-for="(item, index) in scope.data"
				:item-data="item"
				:index="index"
				:key="item.fabricId"
				:columns="columns"
				@click="handleClickDetail(item)"
				@clickBtns="handleClickBtns"
				:buttons="[
					{
						text: '编辑',
						key: 'edit',
						color: 'primary',
					},
					{
						text: '删除',
						key: 'delete',
						color: 'error',
					},
				]"
			/>
		</template>
		<template #summary>
			<xh-summary-box
				:summaryData="summaryData"
				:labelList="[
					{ label: '总卷数', key: 'volumeNum' },
					{ label: '总米数', key: 'meters' },
				]"
			/>
		</template>
	</xh-list-container>
</template>

<script>
import {
	getInboundList,
	deleteFabric,
	getBoundSummary,
} from '@/api/purchase/fabric.js';
import mixins from '../mixins';
// 导入组件
export default {
	name: 'fabricStorage',
	mixins: [mixins],
	data() {
		return {
			request: getInboundList,
			summaryData: {},
			columns: [
				{
					label: '检验编码',
					key: 'insCode',
					width: '100%',
					searchOrder: 3,
					isList: true,
				},
				{
					label: '产品名称',
					key: 'productName',
					valueMapList: [],
					searchOrder: 2,
					isList: true,
				},
				{ label: '卷数', key: 'volumeNum', searchOrder: 4, isList: true },
				{
					label: '入库时间',
					key: 'boundTime',
					searchType: 'daterange',
					searchOrder: 1,
					isList: true,
				},
				{ label: '米数', key: 'meters', searchOrder: 5, isList: true },
				{
					label: '创建时间',
					width: '100%',
					key: 'createTime',
					search: false,
				},
			],
		};
	},
	onShow() {
		this.$refs.pageList?._query();
	},
	mounted() {
		this.columns[1].valueMapList = this.productList;
	},
	methods: {
		handleClickBtns(btnKey, item, index) {
			if (btnKey === 'delete') {
				this.handleDeleteItem(item, index);
			} else if (btnKey === 'edit') {
				this.$nav.navigateTo('/subPurchaseManage/fabricStorage/editForm', item);
			}
		},
		handleClickAdd() {
			this.$nav.navigateTo('/subPurchaseManage/fabricStorage/addForm');
		},
		handleRequest(params) {
			getBoundSummary({ ...params, boundType: 1 }).then((res) => {
				const { data } = res;
				this.summaryData = data || {};
			});
		},
		handleClickDetail(item) {
			this.$nav.navigateTo('/pages/detail/index', {
				...item,
				detailColumns: JSON.stringify(this.columns),
			});
		},
		handleDeleteItem(item) {
			const id = item.fabricId;
			this.$modal.confirm('确定删除吗？').then(() => {
				deleteFabric(id).then(() => {
					this.$modal.msgSuccess('删除成功！');
					this.$refs.pageList?._query();
				});
			});
		},
	},
};
</script>

<style scoped lang="scss"></style>
